import java.io.InputStreamReader;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

import es.deusto.eside.programacion4.mario2d.Mario2D;
import es.deusto.eside.programacion4.mario2d.model.BasicCharacter;
import es.deusto.eside.programacion4.mario2d.model.Mario;


public class prueba extends BasicGame{

	private Mario mario;
	int timer = 0;
	public prueba(String title) {
		super(title);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			AppGameContainer app = new AppGameContainer(new prueba("Mario"));
			app.setVSync(true);
			app.start();
		} catch (SlickException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void render(GameContainer arg0, Graphics arg1) throws SlickException {
		 mario.getCurrent().draw(mario.getPositionX(), mario.getPositionY());
	}

	@Override
	public void init(GameContainer arg0) throws SlickException {
		mario = new Mario();
		mario.setCurrent(mario.getWalk());
		mario.setPositionX(300);
		mario.setPositionY(100);
	}

	@Override
	public void update(GameContainer gc, int arg1) throws SlickException {
		Input i = gc.getInput();
		if(mario.isJump() == true){
        	timer += arg1;
        	if(timer<1000){
        		mario.setPositionY(mario.getPositionY()+5);
        	}
        	else if(timer<2000 && timer >1000){
        		mario.setPositionY(mario.getPositionY()-5);
        		mario.setJump(false);
        	}
        	else{
        		timer = 0;
        		mario.setCurrent(mario.getWalk());
        	}
        }
	        if(i.isKeyDown(Input.KEY_D)){
	        	mario.setCurrent(mario.getWalk());
	            mario.setPositionX(mario.getPositionX()+1);
	        }
	        if(i.isKeyDown(Input.KEY_A)){
	        	mario.setCurrent(mario.getWalkBehind());
	        	mario.setPositionX(mario.getPositionX()-1);
	        }
	        if(i.isKeyDown(Input.KEY_SPACE)){
	        	mario.setCurrent(mario.getJumpSmall());
	        	mario.setJump(true);
	        }
	        

	}

}
